
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Django 3.0 release notes &#8212; Django 3.2.6.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Django 2.2.24 release notes" href="2.2.24.html" />
    <link rel="prev" title="Django 3.0.1 release notes" href="3.0.1.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.6.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="3.0.1.html" title="Django 3.0.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="2.2.24.html" title="Django 2.2.24 release notes">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="releases-3.0">
            
  <div class="section" id="s-django-3-0-release-notes">
<span id="django-3-0-release-notes"></span><h1>Django 3.0 release notes<a class="headerlink" href="#django-3-0-release-notes" title="永久链接至标题">¶</a></h1>
<p><em>December 2, 2019</em></p>
<p>Welcome to Django 3.0!</p>
<p>These release notes cover the <a class="reference internal" href="#whats-new-3-0"><span class="std std-ref">new features</span></a>, as well as
some <a class="reference internal" href="#backwards-incompatible-3-0"><span class="std std-ref">backwards incompatible changes</span></a> you'll
want to be aware of when upgrading from Django 2.2 or earlier. We've
<a class="reference internal" href="#removed-features-3-0"><span class="std std-ref">dropped some features</span></a> that have reached the end of
their deprecation cycle, and we've <a class="reference internal" href="#deprecated-features-3-0"><span class="std std-ref">begun the deprecation process for
some features</span></a>.</p>
<p>See the <a class="reference internal" href="../howto/upgrade-version.html"><span class="doc">升级 Django 到最新的版本</span></a> guide if you're updating an existing
project.</p>
<div class="section" id="s-python-compatibility">
<span id="python-compatibility"></span><h2>Python compatibility<a class="headerlink" href="#python-compatibility" title="永久链接至标题">¶</a></h2>
<p>Django 3.0 supports Python 3.6, 3.7, 3.8, and 3.9 (as of 3.0.11). We <strong>highly
recommend</strong> and only officially support the latest release of each series.</p>
<p>The Django 2.2.x series is the last to support Python 3.5.</p>
</div>
<div class="section" id="s-third-party-library-support-for-older-version-of-django">
<span id="third-party-library-support-for-older-version-of-django"></span><h2>Third-party library support for older version of Django<a class="headerlink" href="#third-party-library-support-for-older-version-of-django" title="永久链接至标题">¶</a></h2>
<p>Following the release of Django 3.0, we suggest that third-party app authors
drop support for all versions of Django prior to 2.2. At that time, you should
be able to run your package's tests using <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-Wd</span></code> so that deprecation
warnings appear. After making the deprecation warning fixes, your app should be
compatible with Django 3.0.</p>
</div>
<div class="section" id="s-what-s-new-in-django-3-0">
<span id="s-whats-new-3-0"></span><span id="what-s-new-in-django-3-0"></span><span id="whats-new-3-0"></span><h2>What's new in Django 3.0<a class="headerlink" href="#what-s-new-in-django-3-0" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-mariadb-support">
<span id="mariadb-support"></span><h3>MariaDB support<a class="headerlink" href="#mariadb-support" title="永久链接至标题">¶</a></h3>
<p>Django now officially supports <a class="reference external" href="https://mariadb.org/">MariaDB</a> 10.1 and
higher. See <a class="reference internal" href="../ref/databases.html#mariadb-notes"><span class="std std-ref">MariaDB notes</span></a> for more details.</p>
</div>
<div class="section" id="s-asgi-support">
<span id="asgi-support"></span><h3>ASGI support<a class="headerlink" href="#asgi-support" title="永久链接至标题">¶</a></h3>
<p>Django 3.0 begins our journey to making Django fully async-capable by providing
support for running as an <a class="reference external" href="https://asgi.readthedocs.io/">ASGI</a> application.</p>
<p>This is in addition to our existing WSGI support. Django intends to support
both for the foreseeable future. Async features will only be available to
applications that run under ASGI, however.</p>
<p>At this stage async support only applies to the outer ASGI application.
Internally everything remains synchronous. Asynchronous middleware, views, etc.
are not yet supported. You can, however, use ASGI middleware around Django's
application, allowing you to combine Django with other ASGI frameworks.</p>
<p>There is no need to switch your applications over unless you want to start
experimenting with asynchronous code, but we have
<a class="reference internal" href="../howto/deployment/asgi/index.html"><span class="doc">documentation on deploying with ASGI</span></a> if
you want to learn more.</p>
<p>Note that as a side-effect of this change, Django is now aware of asynchronous
event loops and will block you calling code marked as &quot;async unsafe&quot; - such as
ORM operations - from an asynchronous context. If you were using Django from
async code before, this may trigger if you were doing it incorrectly. If you
see a <code class="docutils literal notranslate"><span class="pre">SynchronousOnlyOperation</span></code> error, then closely examine your code and
move any database operations to be in a synchronous child thread.</p>
</div>
<div class="section" id="s-exclusion-constraints-on-postgresql">
<span id="exclusion-constraints-on-postgresql"></span><h3>Exclusion constraints on PostgreSQL<a class="headerlink" href="#exclusion-constraints-on-postgresql" title="永久链接至标题">¶</a></h3>
<p>The new <a class="reference internal" href="../ref/contrib/postgres/constraints.html#django.contrib.postgres.constraints.ExclusionConstraint" title="django.contrib.postgres.constraints.ExclusionConstraint"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExclusionConstraint</span></code></a> class
enable adding exclusion constraints on PostgreSQL. Constraints are added to
models using the
<a class="reference internal" href="../ref/models/options.html#django.db.models.Options.constraints" title="django.db.models.Options.constraints"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.constraints</span></code></a> option.</p>
</div>
<div class="section" id="s-filter-expressions">
<span id="filter-expressions"></span><h3>Filter expressions<a class="headerlink" href="#filter-expressions" title="永久链接至标题">¶</a></h3>
<p>Expressions that output <a class="reference internal" href="../ref/models/fields.html#django.db.models.BooleanField" title="django.db.models.BooleanField"><code class="xref py py-class docutils literal notranslate"><span class="pre">BooleanField</span></code></a> may now be
used directly in <code class="docutils literal notranslate"><span class="pre">QuerySet</span></code> filters, without having to first annotate and
then filter against the annotation.</p>
</div>
<div class="section" id="s-enumerations-for-model-field-choices">
<span id="enumerations-for-model-field-choices"></span><h3>Enumerations for model field choices<a class="headerlink" href="#enumerations-for-model-field-choices" title="永久链接至标题">¶</a></h3>
<p>Custom enumeration types <code class="docutils literal notranslate"><span class="pre">TextChoices</span></code>, <code class="docutils literal notranslate"><span class="pre">IntegerChoices</span></code>, and <code class="docutils literal notranslate"><span class="pre">Choices</span></code>
are now available as a way to define <a class="reference internal" href="../ref/models/fields.html#django.db.models.Field.choices" title="django.db.models.Field.choices"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.choices</span></code></a>. <code class="docutils literal notranslate"><span class="pre">TextChoices</span></code>
and <code class="docutils literal notranslate"><span class="pre">IntegerChoices</span></code> types are provided for text and integer fields. The
<code class="docutils literal notranslate"><span class="pre">Choices</span></code> class allows defining a compatible enumeration for other concrete
data types. These custom enumeration types support human-readable labels that
can be translated and accessed via a property on the enumeration or its
members. See <a class="reference internal" href="../ref/models/fields.html#field-choices-enum-types"><span class="std std-ref">Enumeration types</span></a> for more
details and examples.</p>
</div>
<div class="section" id="s-minor-features">
<span id="minor-features"></span><h3>Minor features<a class="headerlink" href="#minor-features" title="永久链接至标题">¶</a></h3>
<div class="section" id="s-django-contrib-admin">
<span id="django-contrib-admin"></span><h4><a class="reference internal" href="../ref/contrib/admin/index.html#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a><a class="headerlink" href="#django-contrib-admin" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added support for the <code class="docutils literal notranslate"><span class="pre">admin_order_field</span></code> attribute on properties in
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.list_display</span></code></a>.</li>
<li>The new <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.get_inlines" title="django.contrib.admin.ModelAdmin.get_inlines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.get_inlines()</span></code></a> method allows specifying the
inlines based on the request or model instance.</li>
<li>Select2 library is upgraded from version 4.0.3 to 4.0.7.</li>
<li>jQuery is upgraded from version 3.3.1 to 3.4.1.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-auth">
<span id="django-contrib-auth"></span><h4><a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a><a class="headerlink" href="#django-contrib-auth" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <code class="docutils literal notranslate"><span class="pre">reset_url_token</span></code> attribute in
<a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.views.PasswordResetConfirmView" title="django.contrib.auth.views.PasswordResetConfirmView"><code class="xref py py-class docutils literal notranslate"><span class="pre">PasswordResetConfirmView</span></code></a> allows
specifying a token parameter displayed as a component of password reset
URLs.</li>
<li>Added <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.backends.BaseBackend" title="django.contrib.auth.backends.BaseBackend"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseBackend</span></code></a> class to ease
customization of authentication backends.</li>
<li>Added <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.get_user_permissions" title="django.contrib.auth.models.User.get_user_permissions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_user_permissions()</span></code></a> method
to mirror the existing
<a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.get_group_permissions" title="django.contrib.auth.models.User.get_group_permissions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_group_permissions()</span></code></a> method.</li>
<li>Added HTML <code class="docutils literal notranslate"><span class="pre">autocomplete</span></code> attribute to widgets of username, email, and
password fields in <a class="reference internal" href="../topics/auth/default.html#module-django.contrib.auth.forms" title="django.contrib.auth.forms"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth.forms</span></code></a> for better interaction
with browser password managers.</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-createsuperuser"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">createsuperuser</span></code></a> now falls back to environment variables for
password and required fields, when a corresponding command line argument
isn't provided in non-interactive mode.</li>
<li><a class="reference internal" href="../topics/auth/customizing.html#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS" title="django.contrib.auth.models.CustomUser.REQUIRED_FIELDS"><code class="xref py py-attr docutils literal notranslate"><span class="pre">REQUIRED_FIELDS</span></code></a> now supports
<a class="reference internal" href="../ref/models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ManyToManyField</span></code></a>s.</li>
<li>The new <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.UserManager.with_perm" title="django.contrib.auth.models.UserManager.with_perm"><code class="xref py py-meth docutils literal notranslate"><span class="pre">UserManager.with_perm()</span></code></a> method returns users that have the
specified permission.</li>
<li>The default iteration count for the PBKDF2 password hasher is increased from
150,000 to 180,000.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-gis">
<span id="django-contrib-gis"></span><h4><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#django-contrib-gis" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Allowed MySQL spatial lookup functions to operate on real geometries.
Previous support was limited to bounding boxes.</li>
<li>Added the <a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.GeometryDistance" title="django.contrib.gis.db.models.functions.GeometryDistance"><code class="xref py py-class docutils literal notranslate"><span class="pre">GeometryDistance</span></code></a>
function, supported on PostGIS.</li>
<li>Added support for the <code class="docutils literal notranslate"><span class="pre">furlong</span></code> unit in
<a class="reference internal" href="../ref/contrib/gis/measure.html#django.contrib.gis.measure.Distance" title="django.contrib.gis.measure.Distance"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distance</span></code></a>.</li>
<li>The <a class="reference internal" href="../ref/contrib/gis/geoip2.html#std:setting-GEOIP_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">GEOIP_PATH</span></code></a> setting now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</li>
<li>The <a class="reference internal" href="../ref/contrib/gis/geoip2.html#django.contrib.gis.geoip2.GeoIP2" title="django.contrib.gis.geoip2.GeoIP2"><code class="xref py py-class docutils literal notranslate"><span class="pre">GeoIP2</span></code></a> class now accepts
<a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> <code class="docutils literal notranslate"><span class="pre">path</span></code>.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-postgres">
<span id="django-contrib-postgres"></span><h4><a class="reference internal" href="../ref/contrib/postgres/index.html#module-django.contrib.postgres" title="django.contrib.postgres: PostgreSQL-specific fields and features"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a><a class="headerlink" href="#django-contrib-postgres" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.RangeOperators" title="django.contrib.postgres.fields.RangeOperators"><code class="xref py py-class docutils literal notranslate"><span class="pre">RangeOperators</span></code></a> helps to
avoid typos in SQL operators that can be used together with
<a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.RangeField" title="django.contrib.postgres.fields.RangeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">RangeField</span></code></a>.</li>
<li>The new <a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.RangeBoundary" title="django.contrib.postgres.fields.RangeBoundary"><code class="xref py py-class docutils literal notranslate"><span class="pre">RangeBoundary</span></code></a> expression
represents the range boundaries.</li>
<li>The new <a class="reference internal" href="../ref/contrib/postgres/operations.html#django.contrib.postgres.operations.AddIndexConcurrently" title="django.contrib.postgres.operations.AddIndexConcurrently"><code class="xref py py-class docutils literal notranslate"><span class="pre">AddIndexConcurrently</span></code></a>
and <a class="reference internal" href="../ref/contrib/postgres/operations.html#django.contrib.postgres.operations.RemoveIndexConcurrently" title="django.contrib.postgres.operations.RemoveIndexConcurrently"><code class="xref py py-class docutils literal notranslate"><span class="pre">RemoveIndexConcurrently</span></code></a>
classes allow creating and dropping indexes <code class="docutils literal notranslate"><span class="pre">CONCURRENTLY</span></code> on PostgreSQL.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-sessions">
<span id="django-contrib-sessions"></span><h4><a class="reference internal" href="../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a><a class="headerlink" href="#django-contrib-sessions" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new
<a class="reference internal" href="../topics/http/sessions.html#django.contrib.sessions.backends.base.SessionBase.get_session_cookie_age" title="django.contrib.sessions.backends.base.SessionBase.get_session_cookie_age"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_session_cookie_age()</span></code></a>
method allows dynamically specifying the session cookie age.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-syndication">
<span id="django-contrib-syndication"></span><h4><a class="reference internal" href="../ref/contrib/syndication.html#module-django.contrib.syndication" title="django.contrib.syndication: A framework for generating syndication feeds, in RSS and Atom, quite easily."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.syndication</span></code></a><a class="headerlink" href="#django-contrib-syndication" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added the <code class="docutils literal notranslate"><span class="pre">language</span></code> class attribute to the
<a class="reference internal" href="../ref/contrib/syndication.html#django.contrib.syndication.views.Feed" title="django.contrib.syndication.views.Feed"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.contrib.syndication.views.Feed</span></code></a> to customize a feed language.
The default value is <a class="reference internal" href="../ref/utils.html#django.utils.translation.get_language" title="django.utils.translation.get_language"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_language()</span></code></a> instead
of <a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_CODE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-cache">
<span id="cache"></span><h4>Cache<a class="headerlink" href="#cache" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/utils.html#django.utils.cache.add_never_cache_headers" title="django.utils.cache.add_never_cache_headers"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_never_cache_headers()</span></code></a> and
<a class="reference internal" href="../topics/http/decorators.html#django.views.decorators.cache.never_cache" title="django.views.decorators.cache.never_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">never_cache()</span></code></a> now add the <code class="docutils literal notranslate"><span class="pre">private</span></code>
directive to <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> headers.</li>
</ul>
</div>
<div class="section" id="s-file-storage">
<span id="file-storage"></span><h4>File Storage<a class="headerlink" href="#file-storage" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/files/storage.html#django.core.files.storage.Storage.get_alternative_name" title="django.core.files.storage.Storage.get_alternative_name"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Storage.get_alternative_name()</span></code></a> method allows customizing the
algorithm for generating filenames if a file with the uploaded name already
exists.</li>
</ul>
</div>
<div class="section" id="s-forms">
<span id="forms"></span><h4>Forms<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Formsets may control the widget used when ordering forms via
<a class="reference internal" href="../topics/forms/formsets.html#django.forms.formsets.BaseFormSet.can_order" title="django.forms.formsets.BaseFormSet.can_order"><code class="xref py py-attr docutils literal notranslate"><span class="pre">can_order</span></code></a> by setting the
<a class="reference internal" href="../topics/forms/formsets.html#django.forms.formsets.BaseFormSet.ordering_widget" title="django.forms.formsets.BaseFormSet.ordering_widget"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ordering_widget</span></code></a> attribute or
overriding <a class="reference internal" href="../topics/forms/formsets.html#django.forms.formsets.BaseFormSet.get_ordering_widget" title="django.forms.formsets.BaseFormSet.get_ordering_widget"><code class="xref py py-attr docutils literal notranslate"><span class="pre">get_ordering_widget()</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-internationalization">
<span id="internationalization"></span><h4>Internationalization<a class="headerlink" href="#internationalization" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added the <a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_HTTPONLY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_HTTPONLY</span></code></a>,
<a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code></a>, and <a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_SECURE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SECURE</span></code></a>
settings to set the <code class="docutils literal notranslate"><span class="pre">HttpOnly</span></code>, <code class="docutils literal notranslate"><span class="pre">SameSite</span></code>, and <code class="docutils literal notranslate"><span class="pre">Secure</span></code> flags on
language cookies. The default values of these settings preserve the previous
behavior.</li>
<li>Added support and translations for the Uzbek language.</li>
</ul>
</div>
<div class="section" id="s-logging">
<span id="logging"></span><h4>Logging<a class="headerlink" href="#logging" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <code class="docutils literal notranslate"><span class="pre">reporter_class</span></code> parameter of
<a class="reference internal" href="../topics/logging.html#django.utils.log.AdminEmailHandler" title="django.utils.log.AdminEmailHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">AdminEmailHandler</span></code></a> allows providing an
<code class="docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporter</span></code> subclass to customize the traceback
text sent to site <a class="reference internal" href="../ref/settings.html#std:setting-ADMINS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ADMINS</span></code></a> when <a class="reference internal" href="../ref/settings.html#std:setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h4>Management Commands<a class="headerlink" href="#management-commands" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-compilemessages-ignore"><code class="xref std std-option docutils literal notranslate"><span class="pre">compilemessages</span> <span class="pre">--ignore</span></code></a> option allows ignoring specific
directories when searching for <code class="docutils literal notranslate"><span class="pre">.po</span></code> files to compile.</li>
<li><a class="reference internal" href="../ref/django-admin.html#cmdoption-showmigrations-list"><code class="xref std std-option docutils literal notranslate"><span class="pre">showmigrations</span> <span class="pre">--list</span></code></a> now shows the applied datetimes when
<code class="docutils literal notranslate"><span class="pre">--verbosity</span></code> is 2 and above.</li>
<li>On PostgreSQL, <a class="reference internal" href="../ref/django-admin.html#django-admin-dbshell"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">dbshell</span></code></a> now supports client-side TLS certificates.</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-inspectdb"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">inspectdb</span></code></a> now introspects <a class="reference internal" href="../ref/models/fields.html#django.db.models.OneToOneField" title="django.db.models.OneToOneField"><code class="xref py py-class docutils literal notranslate"><span class="pre">OneToOneField</span></code></a>
when a foreign key has a unique or primary key constraint.</li>
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-skip-checks"><code class="xref std std-option docutils literal notranslate"><span class="pre">--skip-checks</span></code></a> option skips running system checks prior to
running the command.</li>
<li>The <a class="reference internal" href="../ref/django-admin.html#cmdoption-startapp-template"><code class="xref std std-option docutils literal notranslate"><span class="pre">startapp</span> <span class="pre">--template</span></code></a> and <a class="reference internal" href="../ref/django-admin.html#cmdoption-startproject-template"><code class="xref std std-option docutils literal notranslate"><span class="pre">startproject</span> <span class="pre">--template</span></code></a>
options now support templates stored in XZ archives (<code class="docutils literal notranslate"><span class="pre">.tar.xz</span></code>, <code class="docutils literal notranslate"><span class="pre">.txz</span></code>)
and LZMA archives (<code class="docutils literal notranslate"><span class="pre">.tar.lzma</span></code>, <code class="docutils literal notranslate"><span class="pre">.tlz</span></code>).</li>
</ul>
</div>
<div class="section" id="s-models">
<span id="models"></span><h4>Models<a class="headerlink" href="#models" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first">Added hash database functions <a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.MD5" title="django.db.models.functions.MD5"><code class="xref py py-class docutils literal notranslate"><span class="pre">MD5</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.SHA1" title="django.db.models.functions.SHA1"><code class="xref py py-class docutils literal notranslate"><span class="pre">SHA1</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.SHA224" title="django.db.models.functions.SHA224"><code class="xref py py-class docutils literal notranslate"><span class="pre">SHA224</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.SHA256" title="django.db.models.functions.SHA256"><code class="xref py py-class docutils literal notranslate"><span class="pre">SHA256</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.SHA384" title="django.db.models.functions.SHA384"><code class="xref py py-class docutils literal notranslate"><span class="pre">SHA384</span></code></a>, and
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.SHA512" title="django.db.models.functions.SHA512"><code class="xref py py-class docutils literal notranslate"><span class="pre">SHA512</span></code></a>.</p>
</li>
<li><p class="first">Added the <a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Sign" title="django.db.models.functions.Sign"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sign</span></code></a> database function.</p>
</li>
<li><p class="first">The new <code class="docutils literal notranslate"><span class="pre">is_dst</span></code>  parameter of the
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Trunc" title="django.db.models.functions.Trunc"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trunc</span></code></a> database functions determines the
treatment of nonexistent and ambiguous datetimes.</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">connection.queries</span></code> now shows <code class="docutils literal notranslate"><span class="pre">COPY</span> <span class="pre">…</span> <span class="pre">TO</span></code> statements on PostgreSQL.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/models/fields.html#django.db.models.FilePathField" title="django.db.models.FilePathField"><code class="xref py py-class docutils literal notranslate"><span class="pre">FilePathField</span></code></a> now accepts a callable for <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
</li>
<li><p class="first">Allowed symmetrical intermediate table for self-referential
<a class="reference internal" href="../ref/models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ManyToManyField</span></code></a>.</p>
</li>
<li><p class="first">The <code class="docutils literal notranslate"><span class="pre">name</span></code> attributes of <a class="reference internal" href="../ref/models/constraints.html#django.db.models.CheckConstraint" title="django.db.models.CheckConstraint"><code class="xref py py-class docutils literal notranslate"><span class="pre">CheckConstraint</span></code></a>,
<a class="reference internal" href="../ref/models/constraints.html#django.db.models.UniqueConstraint" title="django.db.models.UniqueConstraint"><code class="xref py py-class docutils literal notranslate"><span class="pre">UniqueConstraint</span></code></a>, and
<a class="reference internal" href="../ref/models/indexes.html#django.db.models.Index" title="django.db.models.Index"><code class="xref py py-class docutils literal notranslate"><span class="pre">Index</span></code></a> now support app label and class
interpolation using the <code class="docutils literal notranslate"><span class="pre">'%(app_label)s'</span></code> and <code class="docutils literal notranslate"><span class="pre">'%(class)s'</span></code> placeholders.</p>
</li>
<li><p class="first">The new <a class="reference internal" href="../ref/models/fields.html#django.db.models.Field.descriptor_class" title="django.db.models.Field.descriptor_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Field.descriptor_class</span></code></a> attribute allows model fields to
customize the get and set behavior by overriding their
<a class="reference external" href="https://docs.python.org/3/reference/datamodel.html#descriptors" title="(在 Python v3.9)"><span class="xref std std-ref">descriptors</span></a>.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/models/querysets.html#django.db.models.Avg" title="django.db.models.Avg"><code class="xref py py-class docutils literal notranslate"><span class="pre">Avg</span></code></a> and <a class="reference internal" href="../ref/models/querysets.html#django.db.models.Sum" title="django.db.models.Sum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sum</span></code></a> now support
the <code class="docutils literal notranslate"><span class="pre">distinct</span></code> argument.</p>
</li>
<li><p class="first">Added <a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallAutoField" title="django.db.models.SmallAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallAutoField</span></code></a> which acts much like an
<a class="reference internal" href="../ref/models/fields.html#django.db.models.AutoField" title="django.db.models.AutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">AutoField</span></code></a> except that it only allows values under
a certain (database-dependent) limit. Values from <code class="docutils literal notranslate"><span class="pre">1</span></code> to <code class="docutils literal notranslate"><span class="pre">32767</span></code> are safe
in all databases supported by Django.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/models/fields.html#django.db.models.AutoField" title="django.db.models.AutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">AutoField</span></code></a>,
<a class="reference internal" href="../ref/models/fields.html#django.db.models.BigAutoField" title="django.db.models.BigAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">BigAutoField</span></code></a>, and
<a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallAutoField" title="django.db.models.SmallAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallAutoField</span></code></a> now inherit from
<code class="docutils literal notranslate"><span class="pre">IntegerField</span></code>, <code class="docutils literal notranslate"><span class="pre">BigIntegerField</span></code> and <code class="docutils literal notranslate"><span class="pre">SmallIntegerField</span></code> respectively.
System checks and validators are now also properly inherited.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/models/fields.html#django.db.models.FileField.upload_to" title="django.db.models.FileField.upload_to"><code class="xref py py-attr docutils literal notranslate"><span class="pre">FileField.upload_to</span></code></a> now supports <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>.</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/models/constraints.html#django.db.models.CheckConstraint" title="django.db.models.CheckConstraint"><code class="xref py py-class docutils literal notranslate"><span class="pre">CheckConstraint</span></code></a> is now supported on MySQL 8.0.16+.</p>
</li>
<li><p class="first">The new <code class="docutils literal notranslate"><span class="pre">allows_group_by_selected_pks_on_model()</span></code> method of
<code class="docutils literal notranslate"><span class="pre">django.db.backends.base.BaseDatabaseFeatures</span></code> allows optimization of
<code class="docutils literal notranslate"><span class="pre">GROUP</span> <span class="pre">BY</span></code> clauses to require only the selected models' primary keys. By
default, it's supported only for managed models on PostgreSQL.</p>
<p>To enable the <code class="docutils literal notranslate"><span class="pre">GROUP</span> <span class="pre">BY</span></code> primary key-only optimization for unmanaged
models, you have to subclass the PostgreSQL database engine, overriding the
features class <code class="docutils literal notranslate"><span class="pre">allows_group_by_selected_pks_on_model()</span></code> method as you
require. See <a class="reference internal" href="../ref/databases.html#subclassing-database-backends"><span class="std std-ref">Subclassing the built-in database backends</span></a> for an example.</p>
</li>
</ul>
</div>
<div class="section" id="s-requests-and-responses">
<span id="requests-and-responses"></span><h4>Requests and Responses<a class="headerlink" href="#requests-and-responses" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Allowed <a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpResponse</span></code></a> to be initialized with
<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#memoryview" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> content.</li>
<li>For use in, for example, Django templates, <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.headers" title="django.http.HttpRequest.headers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">HttpRequest.headers</span></code></a> now
allows lookups using underscores (e.g. <code class="docutils literal notranslate"><span class="pre">user_agent</span></code>) in place of hyphens.</li>
</ul>
</div>
<div class="section" id="s-security">
<span id="s-whats-new-security-3-0"></span><span id="security"></span><span id="whats-new-security-3-0"></span><h4>Security<a class="headerlink" href="#security" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-X_FRAME_OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">'DENY'</span></code>. In older versions, the
<a class="reference internal" href="../ref/settings.html#std:setting-X_FRAME_OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code></a> setting defaults to <code class="docutils literal notranslate"><span class="pre">'SAMEORIGIN'</span></code>. If your site
uses frames of itself, you will need to explicitly set <code class="docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span> <span class="pre">=</span>
<span class="pre">'SAMEORIGIN'</span></code> for them to continue working.</li>
<li><a class="reference internal" href="../ref/settings.html#std:setting-SECURE_CONTENT_TYPE_NOSNIFF"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code>. With this
enabled, <a class="reference internal" href="../ref/middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> sets the
<a class="reference internal" href="../ref/middleware.html#x-content-type-options"><span class="std std-ref">X-Content-Type-Options: nosniff</span></a> header on all responses that do not already
have it.</li>
<li><a class="reference internal" href="../ref/middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> can now send the
<a class="reference internal" href="../ref/middleware.html#referrer-policy"><span class="std std-ref">Referrer-Policy</span></a> header.</li>
</ul>
</div>
<div class="section" id="s-tests">
<span id="tests"></span><h4>Tests<a class="headerlink" href="#tests" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new test <a class="reference internal" href="../topics/testing/tools.html#django.test.Client" title="django.test.Client"><code class="xref py py-class docutils literal notranslate"><span class="pre">Client</span></code></a> argument
<code class="docutils literal notranslate"><span class="pre">raise_request_exception</span></code> allows controlling whether or not exceptions
raised during the request should also be raised in the test. The value
defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code> for backwards compatibility. If it is <code class="docutils literal notranslate"><span class="pre">False</span></code> and an
exception occurs, the test client will return a 500 response with the
attribute <a class="reference internal" href="../topics/testing/tools.html#django.test.Response.exc_info" title="django.test.Response.exc_info"><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_info</span></code></a>, a tuple providing
information of the exception that occurred.</li>
<li>Tests and test cases to run can be selected by test name pattern using the
new <a class="reference internal" href="../ref/django-admin.html#cmdoption-test-k"><code class="xref std std-option docutils literal notranslate"><span class="pre">test</span> <span class="pre">-k</span></code></a> option.</li>
<li>HTML comparison, as used by
<a class="reference internal" href="../topics/testing/tools.html#django.test.SimpleTestCase.assertHTMLEqual" title="django.test.SimpleTestCase.assertHTMLEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertHTMLEqual()</span></code></a>, now treats text, character
references, and entity references that refer to the same character as
equivalent.</li>
<li>Django test runner now supports headless mode for selenium tests on supported
browsers. Add the <code class="docutils literal notranslate"><span class="pre">--headless</span></code> option to enable this mode.</li>
<li>Django test runner now supports <code class="docutils literal notranslate"><span class="pre">--start-at</span></code> and <code class="docutils literal notranslate"><span class="pre">--start-after</span></code> options
to run tests starting from a specific top-level module.</li>
<li>Django test runner now supports a <code class="docutils literal notranslate"><span class="pre">--pdb</span></code> option to spawn a debugger at
each error or failure.</li>
</ul>
</div>
</div>
</div>
<div class="section" id="s-backwards-incompatible-changes-in-3-0">
<span id="s-backwards-incompatible-3-0"></span><span id="backwards-incompatible-changes-in-3-0"></span><span id="backwards-incompatible-3-0"></span><h2>Backwards incompatible changes in 3.0<a class="headerlink" href="#backwards-incompatible-changes-in-3-0" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-model-save-when-providing-a-default-for-the-primary-key">
<span id="model-save-when-providing-a-default-for-the-primary-key"></span><h3><code class="docutils literal notranslate"><span class="pre">Model.save()</span></code> when providing a default for the primary key<a class="headerlink" href="#model-save-when-providing-a-default-for-the-primary-key" title="永久链接至标题">¶</a></h3>
<p><a class="reference internal" href="../ref/models/instances.html#django.db.models.Model.save" title="django.db.models.Model.save"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Model.save()</span></code></a> no longer attempts to find a row when saving a new
<code class="docutils literal notranslate"><span class="pre">Model</span></code> instance and a default value for the primary key is provided, and
always performs a single <code class="docutils literal notranslate"><span class="pre">INSERT</span></code> query. In older Django versions,
<code class="docutils literal notranslate"><span class="pre">Model.save()</span></code> performed either an <code class="docutils literal notranslate"><span class="pre">INSERT</span></code> or an <code class="docutils literal notranslate"><span class="pre">UPDATE</span></code> based on
whether or not the row exists.</p>
<p>This makes calling <code class="docutils literal notranslate"><span class="pre">Model.save()</span></code> while providing a default primary key value
equivalent to passing <a class="reference internal" href="../ref/models/instances.html#ref-models-force-insert"><span class="std std-ref">force_insert=True</span></a> to
model's <code class="docutils literal notranslate"><span class="pre">save()</span></code>. Attempts to use a new <code class="docutils literal notranslate"><span class="pre">Model</span></code> instance to update an
existing row will result in an <code class="docutils literal notranslate"><span class="pre">IntegrityError</span></code>.</p>
<p>In order to update an existing model for a specific primary key value, use the
<a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.update_or_create" title="django.db.models.query.QuerySet.update_or_create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update_or_create()</span></code></a> method or
<code class="docutils literal notranslate"><span class="pre">QuerySet.filter(pk=…).update(…)</span></code> instead. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">MyModel</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">update_or_create</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">existing_pk</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;new name&#39;</span><span class="p">})</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">MyModel</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">existing_pk</span><span class="p">)</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;new name&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-database-backend-api">
<span id="database-backend-api"></span><h3>Database backend API<a class="headerlink" href="#database-backend-api" title="永久链接至标题">¶</a></h3>
<p>This section describes changes that may be needed in third-party database
backends.</p>
<ul class="simple">
<li>The second argument of <code class="docutils literal notranslate"><span class="pre">DatabaseIntrospection.get_geometry_type()</span></code> is now
the row description instead of the column name.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseIntrospection.get_field_type()</span></code> may no longer return tuples.</li>
<li>If the database can create foreign keys in the same SQL statement that adds a
field, add <code class="docutils literal notranslate"><span class="pre">SchemaEditor.sql_create_column_inline_fk</span></code> with the appropriate
SQL; otherwise, set <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.can_create_inline_fk</span> <span class="pre">=</span> <span class="pre">False</span></code>.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.can_return_id_from_insert</span></code> and
<code class="docutils literal notranslate"><span class="pre">can_return_ids_from_bulk_insert</span></code> are renamed to
<code class="docutils literal notranslate"><span class="pre">can_return_columns_from_insert</span></code> and <code class="docutils literal notranslate"><span class="pre">can_return_rows_from_bulk_insert</span></code>.</li>
<li>Database functions now handle <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timezone" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timezone</span></code></a> formats when created
using <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a> instances (e.g.
<code class="docutils literal notranslate"><span class="pre">timezone(timedelta(hours=5))</span></code>, which would output <code class="docutils literal notranslate"><span class="pre">'UTC+05:00'</span></code>).
Third-party backends should handle this format when preparing
<a class="reference internal" href="../ref/models/fields.html#django.db.models.DateTimeField" title="django.db.models.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateTimeField</span></code></a> in <code class="docutils literal notranslate"><span class="pre">datetime_cast_date_sql()</span></code>,
<code class="docutils literal notranslate"><span class="pre">datetime_extract_sql()</span></code>, etc.</li>
<li>Entries for <code class="docutils literal notranslate"><span class="pre">AutoField</span></code>, <code class="docutils literal notranslate"><span class="pre">BigAutoField</span></code>, and <code class="docutils literal notranslate"><span class="pre">SmallAutoField</span></code> are added
to  <code class="docutils literal notranslate"><span class="pre">DatabaseOperations.integer_field_ranges</span></code> to support the integer range
validators on these field types. Third-party backends may need to customize
the default entries.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.fetch_returned_insert_id()</span></code> is replaced by
<code class="docutils literal notranslate"><span class="pre">fetch_returned_insert_columns()</span></code> which returns a list of values returned
by the <code class="docutils literal notranslate"><span class="pre">INSERT</span> <span class="pre">…</span> <span class="pre">RETURNING</span></code> statement, instead of a single value.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.return_insert_id()</span></code> is replaced by
<code class="docutils literal notranslate"><span class="pre">return_insert_columns()</span></code> that accepts a <code class="docutils literal notranslate"><span class="pre">fields</span></code>
argument, which is an iterable of fields to be returned after insert. Usually
this is only the auto-generated primary key.</li>
</ul>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3><a class="reference internal" href="../ref/contrib/admin/index.html#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a><a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>Admin's model history change messages now prefers more readable field labels
instead of field names.</li>
</ul>
</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>Support for PostGIS 2.1 is removed.</li>
<li>Support for SpatiaLite 4.1 and 4.2 is removed.</li>
<li>Support for GDAL 1.11 and GEOS 3.4 is removed.</li>
</ul>
</div>
<div class="section" id="s-dropped-support-for-postgresql-9-4">
<span id="dropped-support-for-postgresql-9-4"></span><h3>Dropped support for PostgreSQL 9.4<a class="headerlink" href="#dropped-support-for-postgresql-9-4" title="永久链接至标题">¶</a></h3>
<p>Upstream support for PostgreSQL 9.4 ends in December 2019. Django 3.0 supports
PostgreSQL 9.5 and higher.</p>
</div>
<div class="section" id="s-dropped-support-for-oracle-12-1">
<span id="dropped-support-for-oracle-12-1"></span><h3>Dropped support for Oracle 12.1<a class="headerlink" href="#dropped-support-for-oracle-12-1" title="永久链接至标题">¶</a></h3>
<p>Upstream support for Oracle 12.1 ends in July 2021. Django 2.2 will be
supported until April 2022. Django 3.0 officially supports Oracle 12.2 and 18c.</p>
</div>
<div class="section" id="s-removed-private-python-2-compatibility-apis">
<span id="removed-private-python-2-compatibility-apis"></span><h3>Removed private Python 2 compatibility APIs<a class="headerlink" href="#removed-private-python-2-compatibility-apis" title="永久链接至标题">¶</a></h3>
<p>While Python 2 support was removed in Django 2.0, some private APIs weren't
removed from Django so that third party apps could continue using them until
the Python 2 end-of-life.</p>
<p>Since we expect apps to drop Python 2 compatibility when adding support for
Django 3.0, we're removing these APIs at this time.</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">django.test.utils.str_prefix()</span></code> - Strings don't have 'u' prefixes in
Python 3.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.test.utils.patch_logger()</span></code> - Use
<a class="reference external" href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertLogs" title="(在 Python v3.9)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestCase.assertLogs()</span></code></a> instead.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.lru_cache.lru_cache()</span></code> - Alias of
<a class="reference external" href="https://docs.python.org/3/library/functools.html#functools.lru_cache" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.lru_cache()</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.decorators.available_attrs()</span></code> - This function returns
<code class="docutils literal notranslate"><span class="pre">functools.WRAPPER_ASSIGNMENTS</span></code>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.decorators.ContextDecorator</span></code> - Alias of
<a class="reference external" href="https://docs.python.org/3/library/contextlib.html#contextlib.ContextDecorator" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.ContextDecorator</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils._os.abspathu()</span></code> - Alias of <a class="reference external" href="https://docs.python.org/3/library/os.path.html#os.path.abspath" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.abspath()</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils._os.upath()</span></code> and <code class="docutils literal notranslate"><span class="pre">npath()</span></code> - These functions do nothing on
Python 3.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.six</span></code> - Remove usage of this vendored library or switch to
<a class="reference external" href="https://pypi.org/project/six/">six</a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.encoding.python_2_unicode_compatible()</span></code> - Alias of
<code class="docutils literal notranslate"><span class="pre">six.python_2_unicode_compatible()</span></code>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.functional.curry()</span></code> - Use <a class="reference external" href="https://docs.python.org/3/library/functools.html#functools.partial" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> or
<a class="reference external" href="https://docs.python.org/3/library/functools.html#functools.partialmethod" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">functools.partialmethod</span></code></a>. See
<a class="reference external" href="https://github.com/django/django/commit/5b1c389603a353625ae1603ba345147356336afb">5b1c389603a353625ae1603ba345147356336afb</a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.safestring.SafeBytes</span></code> - Unused since Django 2.0.</li>
</ul>
</div>
<div class="section" id="s-new-default-value-for-the-file-upload-permissions-setting">
<span id="new-default-value-for-the-file-upload-permissions-setting"></span><h3>New default value for the <code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code> setting<a class="headerlink" href="#new-default-value-for-the-file-upload-permissions-setting" title="永久链接至标题">¶</a></h3>
<p>In older versions, the <a class="reference internal" href="../ref/settings.html#std:setting-FILE_UPLOAD_PERMISSIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code></a> setting defaults to
<code class="docutils literal notranslate"><span class="pre">None</span></code>. With the default <a class="reference internal" href="../ref/settings.html#std:setting-FILE_UPLOAD_HANDLERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FILE_UPLOAD_HANDLERS</span></code></a>, this results in
uploaded files having different permissions depending on their size and which
upload handler is used.</p>
<p><code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code> now defaults to <code class="docutils literal notranslate"><span class="pre">0o644</span></code> to avoid this
inconsistency.</p>
</div>
<div class="section" id="s-new-default-values-for-security-settings">
<span id="new-default-values-for-security-settings"></span><h3>New default values for security settings<a class="headerlink" href="#new-default-values-for-security-settings" title="永久链接至标题">¶</a></h3>
<p>To make Django projects more secure by default, some security settings now have
more secure default values:</p>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-X_FRAME_OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">X_FRAME_OPTIONS</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">'DENY'</span></code>.</li>
<li><a class="reference internal" href="../ref/settings.html#std:setting-SECURE_CONTENT_TYPE_NOSNIFF"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_CONTENT_TYPE_NOSNIFF</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</li>
</ul>
<p>See the <em>What's New</em> <a class="reference internal" href="#whats-new-security-3-0"><span class="std std-ref">Security section</span></a> above for
more details on these changes.</p>
</div>
<div class="section" id="s-miscellaneous">
<span id="miscellaneous"></span><h3>Miscellaneous<a class="headerlink" href="#miscellaneous" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">ContentType.__str__()</span></code> now includes the model's <code class="docutils literal notranslate"><span class="pre">app_label</span></code> to
disambiguate models with the same name in different apps.</li>
<li>Because accessing the language in the session rather than in the cookie is
deprecated, <code class="docutils literal notranslate"><span class="pre">LocaleMiddleware</span></code> no longer looks for the user's language in
the session and <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.logout" title="django.contrib.auth.logout"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.contrib.auth.logout()</span></code></a> no longer preserves the
session's language after logout.</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.html.escape" title="django.utils.html.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.utils.html.escape()</span></code></a> now uses <a class="reference external" href="https://docs.python.org/3/library/html.html#html.escape" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.escape()</span></code></a> to escape HTML.
This converts <code class="docutils literal notranslate"><span class="pre">'</span></code> to <code class="docutils literal notranslate"><span class="pre">&amp;#x27;</span></code> instead of the previous equivalent decimal
code <code class="docutils literal notranslate"><span class="pre">&amp;#39;</span></code>.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">django-admin</span> <span class="pre">test</span> <span class="pre">-k</span></code> option now works as the <a class="reference external" href="https://docs.python.org/3/library/unittest.html#cmdoption-unittest-k" title="(在 Python v3.9)"><code class="xref std std-option docutils literal notranslate"><span class="pre">unittest</span>
<span class="pre">-k</span></code></a> option rather than as a shortcut for <code class="docutils literal notranslate"><span class="pre">--keepdb</span></code>.</li>
<li>Support for <code class="docutils literal notranslate"><span class="pre">pywatchman</span></code> &lt; 1.2.0 is removed.</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.http.urlencode" title="django.utils.http.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlencode()</span></code></a> now encodes iterable values as they are
when <code class="docutils literal notranslate"><span class="pre">doseq=False</span></code>, rather than iterating them, bringing it into line with
the standard library <a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.urlencode()</span></code></a> function.</li>
<li><code class="docutils literal notranslate"><span class="pre">intword</span></code> template filter now translates <code class="docutils literal notranslate"><span class="pre">1.0</span></code> as a singular phrase and
all other numeric values as plural. This may be incorrect for some languages.</li>
<li>Assigning a value to a model's <a class="reference internal" href="../ref/models/fields.html#django.db.models.ForeignKey" title="django.db.models.ForeignKey"><code class="xref py py-class docutils literal notranslate"><span class="pre">ForeignKey</span></code></a> or
<a class="reference internal" href="../ref/models/fields.html#django.db.models.OneToOneField" title="django.db.models.OneToOneField"><code class="xref py py-class docutils literal notranslate"><span class="pre">OneToOneField</span></code></a> <code class="docutils literal notranslate"><span class="pre">'_id'</span></code> attribute now unsets the
corresponding field. Accessing the field afterwards will result in a query.</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.cache.patch_vary_headers" title="django.utils.cache.patch_vary_headers"><code class="xref py py-func docutils literal notranslate"><span class="pre">patch_vary_headers()</span></code></a> now handles an asterisk
<code class="docutils literal notranslate"><span class="pre">'*'</span></code> according to <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7231.html#section-7.1.4"><strong>RFC 7231#section-7.1.4</strong></a>, i.e. if a list of header
field names contains an asterisk, then the <code class="docutils literal notranslate"><span class="pre">Vary</span></code> header will consist of a
single asterisk <code class="docutils literal notranslate"><span class="pre">'*'</span></code>.</li>
<li>On MySQL 8.0.16+, <code class="docutils literal notranslate"><span class="pre">PositiveIntegerField</span></code> and <code class="docutils literal notranslate"><span class="pre">PositiveSmallIntegerField</span></code>
now include a check constraint to prevent negative values in the database.</li>
<li><code class="docutils literal notranslate"><span class="pre">alias=None</span></code> is added to the signature of
<a class="reference internal" href="../ref/models/expressions.html#django.db.models.Expression.get_group_by_cols" title="django.db.models.Expression.get_group_by_cols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Expression.get_group_by_cols()</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">RegexPattern</span></code>, used by <a class="reference internal" href="../ref/urls.html#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">re_path()</span></code></a>, no longer returns
keyword arguments with <code class="docutils literal notranslate"><span class="pre">None</span></code> values to be passed to the view for the
optional named groups that are missing.</li>
</ul>
</div>
</div>
<div class="section" id="s-features-deprecated-in-3-0">
<span id="s-deprecated-features-3-0"></span><span id="features-deprecated-in-3-0"></span><span id="deprecated-features-3-0"></span><h2>Features deprecated in 3.0<a class="headerlink" href="#features-deprecated-in-3-0" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-django-utils-encoding-force-text-and-smart-text">
<span id="django-utils-encoding-force-text-and-smart-text"></span><h3><code class="docutils literal notranslate"><span class="pre">django.utils.encoding.force_text()</span></code> and <code class="docutils literal notranslate"><span class="pre">smart_text()</span></code><a class="headerlink" href="#django-utils-encoding-force-text-and-smart-text" title="永久链接至标题">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">smart_text()</span></code> and <code class="docutils literal notranslate"><span class="pre">force_text()</span></code> aliases (since Django 2.0) of
<code class="docutils literal notranslate"><span class="pre">smart_str()</span></code> and <code class="docutils literal notranslate"><span class="pre">force_str()</span></code> are deprecated. Ignore this deprecation if
your code supports Python 2 as the behavior of <code class="docutils literal notranslate"><span class="pre">smart_str()</span></code> and
<code class="docutils literal notranslate"><span class="pre">force_str()</span></code> is different there.</p>
</div>
<div class="section" id="s-id3">
<span id="id3"></span><h3>Miscellaneous<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">django.utils.http.urlquote()</span></code>, <code class="docutils literal notranslate"><span class="pre">urlquote_plus()</span></code>, <code class="docutils literal notranslate"><span class="pre">urlunquote()</span></code>, and
<code class="docutils literal notranslate"><span class="pre">urlunquote_plus()</span></code> are deprecated in favor of the functions that they're
aliases for: <a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.quote()</span></code></a>, <a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote_plus()</span></code></a>,
<a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">unquote()</span></code></a>, and <a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.unquote_plus" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">unquote_plus()</span></code></a>.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.translation.ugettext()</span></code>, <code class="docutils literal notranslate"><span class="pre">ugettext_lazy()</span></code>,
<code class="docutils literal notranslate"><span class="pre">ugettext_noop()</span></code>, <code class="docutils literal notranslate"><span class="pre">ungettext()</span></code>, and <code class="docutils literal notranslate"><span class="pre">ungettext_lazy()</span></code> are deprecated
in favor of the functions that they're aliases for:
<a class="reference internal" href="../ref/utils.html#django.utils.translation.gettext" title="django.utils.translation.gettext"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.utils.translation.gettext()</span></code></a>,
<a class="reference internal" href="../ref/utils.html#django.utils.translation.gettext_lazy" title="django.utils.translation.gettext_lazy"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettext_lazy()</span></code></a>,
<a class="reference internal" href="../ref/utils.html#django.utils.translation.gettext_noop" title="django.utils.translation.gettext_noop"><code class="xref py py-func docutils literal notranslate"><span class="pre">gettext_noop()</span></code></a>,
<a class="reference internal" href="../ref/utils.html#django.utils.translation.ngettext" title="django.utils.translation.ngettext"><code class="xref py py-func docutils literal notranslate"><span class="pre">ngettext()</span></code></a>, and
<a class="reference internal" href="../ref/utils.html#django.utils.translation.ngettext_lazy" title="django.utils.translation.ngettext_lazy"><code class="xref py py-func docutils literal notranslate"><span class="pre">ngettext_lazy()</span></code></a>.</li>
<li>To limit creation of sessions and hence favor some caching strategies,
<a class="reference internal" href="../topics/i18n/translation.html#django.views.i18n.set_language" title="django.views.i18n.set_language"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.views.i18n.set_language()</span></code></a> will stop setting the user's language
in the session in Django 4.0. Since Django 2.1, the language is always stored
in the <a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_NAME"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_NAME</span></code></a> cookie.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.text.unescape_entities()</span></code> is deprecated in favor of
<a class="reference external" href="https://docs.python.org/3/library/html.html#html.unescape" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.unescape()</span></code></a>. Note that unlike <code class="docutils literal notranslate"><span class="pre">unescape_entities()</span></code>,
<code class="docutils literal notranslate"><span class="pre">html.unescape()</span></code> evaluates lazy strings immediately.</li>
<li>To avoid possible confusion as to effective scope, the private internal
utility <code class="docutils literal notranslate"><span class="pre">is_safe_url()</span></code> is renamed to
<code class="docutils literal notranslate"><span class="pre">url_has_allowed_host_and_scheme()</span></code>. That a URL has an allowed host and
scheme doesn't in general imply that it's &quot;safe&quot;. It may still be quoted
incorrectly, for example. Ensure to also use
<a class="reference internal" href="../ref/utils.html#django.utils.encoding.iri_to_uri" title="django.utils.encoding.iri_to_uri"><code class="xref py py-func docutils literal notranslate"><span class="pre">iri_to_uri()</span></code></a> on the path component of untrusted
URLs.</li>
</ul>
</div>
</div>
<div class="section" id="s-features-removed-in-3-0">
<span id="s-removed-features-3-0"></span><span id="features-removed-in-3-0"></span><span id="removed-features-3-0"></span><h2>Features removed in 3.0<a class="headerlink" href="#features-removed-in-3-0" title="永久链接至标题">¶</a></h2>
<p>These features have reached the end of their deprecation cycle and are removed
in Django 3.0.</p>
<p>See <a class="reference internal" href="2.0.html#deprecated-features-2-0"><span class="std std-ref">Features deprecated in 2.0</span></a> for details on these changes, including how
to remove usage of these features.</p>
<ul class="simple">
<li>The <code class="docutils literal notranslate"><span class="pre">django.db.backends.postgresql_psycopg2</span></code> module is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.shortcuts.render_to_response()</span></code> is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">DEFAULT_CONTENT_TYPE</span></code> setting is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">HttpRequest.xreadlines()</span></code> is removed.</li>
<li>Support for the <code class="docutils literal notranslate"><span class="pre">context</span></code> argument of <code class="docutils literal notranslate"><span class="pre">Field.from_db_value()</span></code> and
<code class="docutils literal notranslate"><span class="pre">Expression.convert_value()</span></code> is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">field_name</span></code> keyword argument of <code class="docutils literal notranslate"><span class="pre">QuerySet.earliest()</span></code> and
<code class="docutils literal notranslate"><span class="pre">latest()</span></code> is removed.</li>
</ul>
<p>See <a class="reference internal" href="2.1.html#deprecated-features-2-1"><span class="std std-ref">Features deprecated in 2.1</span></a> for details on these changes, including how
to remove usage of these features.</p>
<ul class="simple">
<li>The <code class="docutils literal notranslate"><span class="pre">ForceRHR</span></code> GIS function is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.http.cookie_date()</span></code> is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> and <code class="docutils literal notranslate"><span class="pre">admin_static</span></code> template tag libraries are removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.templatetags.staticfiles.static()</span></code> is removed.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django 3.0 release notes</a><ul>
<li><a class="reference internal" href="#python-compatibility">Python compatibility</a></li>
<li><a class="reference internal" href="#third-party-library-support-for-older-version-of-django">Third-party library support for older version of Django</a></li>
<li><a class="reference internal" href="#what-s-new-in-django-3-0">What's new in Django 3.0</a><ul>
<li><a class="reference internal" href="#mariadb-support">MariaDB support</a></li>
<li><a class="reference internal" href="#asgi-support">ASGI support</a></li>
<li><a class="reference internal" href="#exclusion-constraints-on-postgresql">Exclusion constraints on PostgreSQL</a></li>
<li><a class="reference internal" href="#filter-expressions">Filter expressions</a></li>
<li><a class="reference internal" href="#enumerations-for-model-field-choices">Enumerations for model field choices</a></li>
<li><a class="reference internal" href="#minor-features">Minor features</a><ul>
<li><a class="reference internal" href="#django-contrib-admin"><code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-auth"><code class="docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-gis"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-postgres"><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-sessions"><code class="docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-syndication"><code class="docutils literal notranslate"><span class="pre">django.contrib.syndication</span></code></a></li>
<li><a class="reference internal" href="#cache">Cache</a></li>
<li><a class="reference internal" href="#file-storage">File Storage</a></li>
<li><a class="reference internal" href="#forms">Forms</a></li>
<li><a class="reference internal" href="#internationalization">Internationalization</a></li>
<li><a class="reference internal" href="#logging">Logging</a></li>
<li><a class="reference internal" href="#management-commands">Management Commands</a></li>
<li><a class="reference internal" href="#models">Models</a></li>
<li><a class="reference internal" href="#requests-and-responses">Requests and Responses</a></li>
<li><a class="reference internal" href="#security">Security</a></li>
<li><a class="reference internal" href="#tests">Tests</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#backwards-incompatible-changes-in-3-0">Backwards incompatible changes in 3.0</a><ul>
<li><a class="reference internal" href="#model-save-when-providing-a-default-for-the-primary-key"><code class="docutils literal notranslate"><span class="pre">Model.save()</span></code> when providing a default for the primary key</a></li>
<li><a class="reference internal" href="#database-backend-api">Database backend API</a></li>
<li><a class="reference internal" href="#id1"><code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a></li>
<li><a class="reference internal" href="#id2"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#dropped-support-for-postgresql-9-4">Dropped support for PostgreSQL 9.4</a></li>
<li><a class="reference internal" href="#dropped-support-for-oracle-12-1">Dropped support for Oracle 12.1</a></li>
<li><a class="reference internal" href="#removed-private-python-2-compatibility-apis">Removed private Python 2 compatibility APIs</a></li>
<li><a class="reference internal" href="#new-default-value-for-the-file-upload-permissions-setting">New default value for the <code class="docutils literal notranslate"><span class="pre">FILE_UPLOAD_PERMISSIONS</span></code> setting</a></li>
<li><a class="reference internal" href="#new-default-values-for-security-settings">New default values for security settings</a></li>
<li><a class="reference internal" href="#miscellaneous">Miscellaneous</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-deprecated-in-3-0">Features deprecated in 3.0</a><ul>
<li><a class="reference internal" href="#django-utils-encoding-force-text-and-smart-text"><code class="docutils literal notranslate"><span class="pre">django.utils.encoding.force_text()</span></code> and <code class="docutils literal notranslate"><span class="pre">smart_text()</span></code></a></li>
<li><a class="reference internal" href="#id3">Miscellaneous</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-removed-in-3-0">Features removed in 3.0</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="3.0.1.html"
                        title="上一章">Django 3.0.1 release notes</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="2.2.24.html"
                        title="下一章">Django 2.2.24 release notes</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/releases/3.0.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">7月 23, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="3.0.1.html" title="Django 3.0.1 release notes">previous</a>
     |
    <a href="index.html" title="Release notes" accesskey="U">up</a>
   |
    <a href="2.2.24.html" title="Django 2.2.24 release notes">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>